package com.itheima.reggie.Service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.Dao.OrdersDao;
import com.itheima.reggie.Service.OrdersService;

import com.itheima.reggie.bean.Orders;


import com.itheima.reggie.common.PageParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * @author LiuKeLin
 * @title: OrdersServiceImpl
 * @projectName itcaset_reggie
 * @description: TODO
 * @date 2022/1/510:31
 */
@Service
public class OrdersServiceImpl implements OrdersService {

    @Autowired
    private OrdersDao ordersDao;

    @Override
    public IPage<Orders> page(PageParam pageParam) {
        //创建分页对象
        IPage<Orders> page = new Page<>(pageParam.getPage(), pageParam.getPageSize());
        //条件构造器
        LambdaQueryWrapper<Orders> lqw = new LambdaQueryWrapper<>();
        lqw.like((pageParam.getNumber() != null), Orders::getNumber, pageParam.getNumber());

        /*lqw.ge((pageParam.getBeginTime() != null), Orders::getOrderTime, pageParam.getBeginTime());

        lqw.le((pageParam.getBeginTime() != null), Orders::getOrderTime,pageParam.getEndTime());*/

        lqw.between((pageParam.getBeginTime() != null),Orders::getOrderTime,pageParam.getBeginTime(),pageParam.getEndTime());
        //查询的数据
        ordersDao.selectPage(page, lqw);

        return page;
    }

    @Override
    public int update(Orders orders) {
        int rows =ordersDao.updateById(orders);
        return rows;
    }

}
